<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
>
<head>
    <!-- 设置页面的 基本路径，页面所有资源引入和页面的跳转全部基于 base路径 -->
    <base th:href="${#request.getContextPath()}+'/'">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>

    <script type="text/javascript" th:src="@{/lib/html5shiv.js}"></script>
    <script type="text/javascript" th:src="@{/lib/respond.min.js}"></script>


    <link rel="stylesheet" type="text/css" th:href="@{/h-ui/css/H-ui.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/css/H-ui.admin.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/Hui-iconfont/1.0.8/iconfont.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/skin/default/skin.css}" id="skin"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/css/style.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap/css/bootstrap.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap-table/bootstrap-table.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}"/>

    <script type="text/javascript" th:src="@{/lib/DD_belatedPNG_0.0.8a-min.js}"></script>
    <script>DD_belatedPNG.fix('*');</script>


    <style type="text/css">
        #toolbar a {
            margin: 0 5px;
        }

        #patient-right div, #patient-bottom div {
            float: left;
            width: 50%;
            line-height: 40px;
            text-align: center;
        }
    </style>
</head>
<body style="background-color:rgb(243, 245, 248)">
<nav class="breadcrumb" style="margin-bottom: 5px"><i class="fa fa-plus-square"></i>&nbsp; 看病就诊 <span
        class="c-gray en">&gt;</span> 新开就诊
</nav>
<div class="container-fluid " style="position: relative;height: 32px">
    <span id="toolbar" style="position:absolute;top:auto;right: 35px">
         <shiro:hasPermission name="dept:insert">
            <a href="javascript:;" onclick="dept_add()"
               class="btn btn-secondary radius">历史</a>
         </shiro:hasPermission>
         <shiro:hasPermission name="dept:insert">
            <a href="javascript:;" onclick="newVisitAdd()"
               class="btn btn-success  radius">保存</a>
         </shiro:hasPermission>
         <shiro:hasPermission name="dept:insert">
            <a href="javascript:;" onclick="dept_add()"
               class="btn btn-warning  radius">收费</a>
         </shiro:hasPermission>
    </span>
</div>

<!--格式化标签-->
<div id="operateDiv" style="display: none;">
    <shiro:hasPermission name="dept:update">
        <a title="编辑" href="javascript:;" id="dept_edit" value="" onclick="dept_edit(this)"
           style="text-decoration:none"><i class="Hui-iconfont"></i></a>
    </shiro:hasPermission>
    <shiro:hasPermission name="dept:delete">
        <a title="删除" href="javascript:;" id="dept_delete" value="" onclick="dept_del(this)" class="ml-5"
           style="text-decoration:none"><i class="Hui-iconfont"></i></a>
    </shiro:hasPermission>
</div>
<!--格式化标签-->

<div class="container-fluid"
     style="position: relative;box-shadow:2px 2px 1px rgb(229, 231, 233) ;border-radius:2px;margin:5px 35px;right: 0;height: 650px;border: rgb(255, 255, 255) solid 2px">
    <div class="row">
        <!--左边布局-->
        <div class="col-md-4" style="background-color: rgb(248, 248, 248);">
            <div style="height: 400px;overflow-y: auto;overflow-x: hidden">
                <h4 style="color:rgb(66, 155, 255)">患者信息</h4>
                <form class="form form-horizontal" action="newVisit/saveOrUpdate"
                      method="post" id="form-patients-add">
                    <input type="hidden" id="patientsId" value="" name="patientsId" th:value=" ${session.choosePatient != null} ? ${session.choosePatient.patientsId}">
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">姓名：</label>
                        <div class="formControls col-xs-8 col-sm-6">
                            <input type="text" class="input-text" th:value=" ${session.choosePatient != null} ? ${session.choosePatient.patientsName}"
                                   placeholder="" id="patientsName" name="patientsName">
                        </div>
                        <a onclick="showPatientsRegistered()"><i class="fa fa-user" style="line-height: 30px"></i></a>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-3 col-sm-3">性别：</label>
                        <div class="formControls col-xs-3 col-sm-3">
                        <span class="select-box" style="width:150px;">
                            <select class="select" name="patientsGender" size="1">
                                <option value="">请选择性别</option>
                                <option th:selected="${session.choosePatient ne null}? (${session.choosePatient.patientsGender} eq '男')" value="男">男</option>
                                <option th:selected="${session.choosePatient ne null}? (${session.choosePatient.patientsGender} eq '女')" value="女">女</option>
                            </select>
                        </span>
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">年龄：</label>
                        <div class="formControls col-xs-8 col-sm-6">
                            <input type="text" class="input-text" th:value=" ${session.choosePatient != null} ? ${session.choosePatient.patientsAge}"
                                   placeholder="" id="patientsAge" name="patientsAge">
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">手机：</label>
                        <div class="formControls col-xs-8 col-sm-6">
                            <input type="text" class="input-text" th:value=" ${session.choosePatient != null} ? ${session.choosePatient.patientsPhone}"
                                   onblur="searchPatinets(this)" id="patientsPhone" name="patientsPhone">
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">身份证：</label>
                        <div class="formControls col-xs-8 col-sm-6">
                            <input type="text" class="input-text" th:value=" ${session.choosePatient != null} ? ${session.choosePatient.patientsIdcard}"
                                   onblur="changeIdcard(this)"  id="patientsIdcard" name="patientsIdcard">
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">住址：</label>
                        <div class="formControls col-xs-8 col-sm-6">
                    <textarea class="form-control" rows="2" name="patientsAddress"
                             id="patientsAddress"  th:value=" ${session.choosePatient != null} ? ${session.choosePatient.patientsAddress}"  placeholder="填写当前住址（限100字）"></textarea>
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">过敏史：</label>
                        <div class="formControls col-xs-8 col-sm-6">
                    <textarea class="form-control" rows="2" id="patientsAllergy" name="patientsAllergy"
                              th:value=" ${session.choosePatient != null} ? ${session.choosePatient.patientsAllergy}"  placeholder="填写本次诊断详情（限500字）"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div style="height: 245px;">
                <div id="patient-bottom" style="width: 100%;overflow: auto">
                    <div id="archives" style="background-color: #00b7ee;cursor: pointer" onclick="changeArchives()">
                        患者档案
                    </div>
                    <div id="history" style="background-color:rgb(229, 229, 229);cursor: pointer"
                         onclick="changeHistory()">病例历史
                    </div>
                </div>
                <div id="patient-bottom-table" style="overflow: auto;height: 200px">
                    <table id="dataTable-archives"  class="table table-border table-bordered table-bg">
                    </table>
                    <table id="dataTable-history" style="display: none"
                           class="table table-border table-bordered table-bg">
                    </table>

                </div>
            </div>
        </div>
        <!--右边布局-->
        <div class="col-md-8" style="background-color: rgb(255, 255, 255);height: 645px;overflow: auto">
            <div id="patient-right" style="width: 100%;">
                <div id="medical-record" style="background-color: #00b7ee;cursor: pointer"
                     onclick="changeMedicalRecord()">病历
                </div>
                <div id="case-order" style="background-color:rgb(229, 229, 229);cursor: pointer"
                     onclick="changeCaseOrder()">处方
                </div>
            </div>
            <!--病历表单-->
            <div id="medical-record-from"  class="row cl">
                <form  id="form-patientCase-add" action="newVisit/insertPatientCase" class="form form-horizontal"  method="post">
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-2" style="color: #00b7ee">诊断信息</label>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">诊断编号：</label>
                    <span id="patient-number"></span>
                </div>

                <!--诊断编号-->
                <input type="hidden" name="diagnoseNumber" id="diagnoseNumber" value="">
                <!--患者身份证-->
                <input type="hidden" name="patientsCaseIdCard" id="patientsCaseIdCard" value="">

                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">发病日期：</label>
                    <div class="formControls col-xs-8 col-sm-6">
                        <input type="date" class="input-date" name="morbidityDate">
                    </div>
                </div>

                <div class="row cl">
                    <label class="form-label col-xs-3 col-sm-3">接诊类型：</label>
                    <div class="formControls col-xs-3 col-sm-3">
                        <span class="select-box" style="width:150px;">
                            <select class="select" name="acceptsType" size="1">
                                <option value="初诊">初诊</option>
                                <option value="复诊">复诊</option>
                                <option value="急诊">急诊</option>
                            </select>
                        </span>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-3 col-sm-3">是否传染：</label>
                    <div class="formControls col-xs-3 col-sm-3">
                        <span class="select-box" style="width:150px;">
                            <select class="select" name="transmission" size="1">
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </span>
                    </div>
                </div>


                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">主诉：</label>
                    <div class="formControls col-xs-8 col-sm-6">
                    <textarea class="form-control" rows="3" name="caseTitle"
                              placeholder="填写主诉病状（限500字）"></textarea>
                    </div>
                </div>

                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">诊断详情：</label>
                    <div class="formControls col-xs-8 col-sm-6">
                    <textarea class="form-control" rows="3" name="caseResult"
                              placeholder="填写本次诊断详情（限500字）"></textarea>
                    </div>
                </div>

                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">医生建议：</label>
                    <div class="formControls col-xs-8 col-sm-6">
                    <textarea class="form-control" rows="3" name="doctorTips"
                          placeholder="医生建议（限500字）"></textarea>
                    </div>
                </div>

                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">备注：</label>
                    <div class="formControls col-xs-8 col-sm-6">
                    <textarea class="form-control" rows="3" name="caseDesc"
                              placeholder="填写备注（限500字）"></textarea>
                    </div>
                </div>
            </form>
            </div>
            <!--处方表单-->
            <div id="case-order-from" class="row cl" style="display: none;">
                <label id="myNum">处方编号：</label><br/>
                <span>
                        <a id="case-order-add" href="javascript:;" onclick="chose_case_order_form(this)"
                           class="btn btn-success radius">处方1</a>
                 </span>
                <a href="javascript:;" onclick="add_case_order_form()"
                   class="btn btn-warning  radius">+</a>
                <form id="form-case-order" class="form form-horizontal" action="newVisit/insertCaseOrder" method="post">
                    <!--患者身份证-->
                    <input type="hidden" id="caseOrderIdCaer" name="caseOrderIdCaer" >
                    <!--处方编号-->
                    <input type="hidden" id="caseOrderNumber" name="caseOrderNumber" >
                    <!--药品表编号-->
                    <input type="hidden" id="caseOrderTmpIds" name="caseOrderTmpIds" >
                    <table id="dataTable-case-order-tmp" style="margin-top: 10px;height: 50px;display: none"
                           class="table table-border table-bordered table-bg"></table>
                    <div id="medicine_add" class="row cl" style="width: 100%;padding-left: 15px">
                        <a href="javascript:;" style="width: 100%" onclick="case_order_add_medicine()"
                           class="btn btn-secondary radius">添加药品</a>
                    </div>

                    <!--检查项目表格-->
                    <input type="hidden" id="caseOrderTmpOneIds" name="caseOrderTmpOneIds" >
                    <table id="dataTable-case-order-tmp-one" style="margin-top: 10px;height: 50px;display: none"
                           class="table table-border table-bordered table-bg"></table>
                    <div id="check_add" class="row cl" style="width: 100%;padding-left: 15px">
                        <a href="javascript:;" style="width: 100%" onclick="case_order_add_check()"
                           class="btn btn-warning radius">添加检查项目</a>
                    </div>

                   <!--处方附加费表格-->
                    <input type="hidden" id="caseOrderTmpTwoIds" name="caseOrderTmpTwoIds">
                    <table id="dataTable-case-order-tmp-two" style="margin-top: 10px;display: none"
                           class="table table-border table-bordered table-bg"></table>
                    <div class="row cl" style="width: 100%;padding-left: 15px">
                        <a href="javascript:;" style="width: 100%" onclick="add_prescription_surcharge()"
                           class="btn btn-success radius">附加费用</a>
                    </div>

                    <div class="row cl">
                        <label style="padding-left: 15px">服药要求：</label>
                        <div style="padding-left: 15px">
                    <textarea style="width: 800px" class="form-control" rows="3" name="medicineRequirement"
                              placeholder="请填写服药要求（限500字）"></textarea>
                        </div>
                    </div>

                    <div class="row cl">
                        <label style="padding-left: 15px">中药备注：</label>
                        <div style="padding-left: 15px">
                    <textarea style="width: 800px " class="form-control" rows="3" name="tcmRemark"
                              placeholder="请填写中药备注（限500字）"></textarea>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>

<script type="text/javascript" th:src="@{/lib/jquery/1.11.3/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/layer/2.4/layer.js}"></script>
<script type="text/javascript" th:src="@{/h-ui/js/H-ui.min.js}"></script>
<script type="text/javascript" th:src="@{/h-ui.admin/js/H-ui.admin.js}"></script> <!--/_footer 作为公共模版分离出去-->


<script type="text/javascript" th:src="@{/lib/My97DatePicker/4.8/WdatePicker.js}"></script>
<script type="text/javascript" th:src="@{/lib/datatables/1.10.0/jquery.dataTables.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/bootstrap-table/bootstrap-table.js}"></script>
<script type="text/javascript" th:src="@{/lib/bootstrap-table/bootstrap-table-zh-CN.min.js}"></script>
<script type="text/javascript" th:src="@{lib/jquery.validation/1.14.0/jquery.validate.js}"></script>

<!--datatable-->
<script type="text/javascript">
    $(function () {
        //处方编号
        var sourceStr = "0,1,2,3,4,5,6,7,8,9";
        arrStr = sourceStr.split(",");
        var result = ""; //定义变量并初始化
        var index = 0;
        for (i = 0; i < 13; i++) {
            index = parseInt(Math.random() * arrStr.length);
            result += arrStr[index];
        }
        $("#myNum").text($("#myNum").text() + "  " + result)
        $("#caseOrderNumber").val(result)

        //处方-药品表
        $('#dataTable-case-order-tmp').bootstrapTable({
            url: 'newVisit/getMedicineInfo?caseOrderNumber='+result,//ajax请求的url地址
            pagination: true,
            pageNumber: 1,
            pageSize: 3,
            paginationHAlign: 'right', //底部分页条
            columns: [ //表格显示数据对应的表头设置，
                {field: 'careOrderTmpId', title: '序号'},
                {field: 'medicineName', title: '药品名'},
                {field: 'number', title: '数量'},
                {field: 'price', title: '单价（元）'},
                {field: 'totalMoney', title: '金额（元）'},
                {field: 'specialRequirements', title: '特殊要求'},
                {
                    field: 'careOrderTmpId',
                    title: '操作',
                    align: 'center',
                    formatter: getOperateBtns

                }
            ]
        });

        $('#dataTable-case-order-tmp-one').bootstrapTable({
            url: 'newVisit/getCheck?caseOrderNumber='+result,//ajax请求的url地址
            columns: [ //表格显示数据对应的表头设置，
                {field: 'checkId', title: '序号'},
                {field: 'checkName', title: '名称'},
                {field: 'checkMoney', title: '单价'},
                {field: 'checkCost', title: '最小单位'},
                {
                    field: 'checkId',
                    title: '操作',
                    align: 'center',
                    formatter: getOperateBtns

                }
            ]
        });

        //处方 - 附加费表
        $('#dataTable-case-order-tmp-two').bootstrapTable({
            url: 'newVisit/getPrescriptionSurcharge?caseOrderNumber='+result,//ajax请求的url地址
            columns: [ //表格显示数据对应的表头设置，
                {field: 'surchargeId', title: '序号'},
                {field: 'surchargeTypeName', title: '药品名称'},
                {field: 'surchargeMoney', title: '金额'},
                {field: 'typeName', title: '处方类型'},
                {
                    field: 'surchargeId',
                    title: '操作',
                    align: 'center',
                    formatter: getOperateBtns

                }
            ]
        });

        function getOperateBtns(value, row, index) {
            var html = "";
            $("#operateDiv").find("a").each(function () {
                var myA = $(this).clone()
                myA.attr("value", row.deptId)
                html += myA.prop("outerHTML") + "&nbsp;&nbsp;&nbsp;&nbsp;";

            });

            return html;
        }
    });
</script>

<!--布局-->
<script>


    $(function () {
        //病历表的诊断编号
        var sourceStr = "0,1,2,3,4,5,6,7,8,9";
        arrStr = sourceStr.split(",");
        var result = ""; //定义变量并初始化
        var index = 0;
        for (i = 0; i < 5; i++) {
            index = parseInt(Math.random() * arrStr.length);
            result += arrStr[index];
        }
        $("#patient-number").text(result)
        $("#diagnoseNumber").val(result)

    })
    $(function () {
        //设置患者文本域回显
        $("#patientsAddress").val( $("#patientsAddress").attr("value"))
        $("#patientsAllergy").val( $("#patientsAllergy").attr("value"))
    })
    //改变患者信息的样式
    function changeArchives() {
        $("#dataTable-archives").attr("style", "display:table;")
        $("#history").attr("style", "background-color:rgb(229, 229, 229);cursor: pointer")
        $("#dataTable-history").attr("style", "display:none;")
        $("#archives").attr("style", "background-color: #00b7ee;cursor: pointer")
    }

    function changeHistory() {
        $("#dataTable-archives").attr("style", "display:none;")
        $("#history").attr("style", "background-color: #00b7ee;cursor: pointer")
        $("#dataTable-history").attr("style", "display:table;")
        $("#archives").attr("style", "background-color:rgb(229, 229, 229);cursor: pointer")
    }

    //改变右边布局的样式
    function changeMedicalRecord() {
        $("#case-order").attr("style", "background-color:rgb(229, 229, 229);cursor: pointer")
        $("#medical-record").attr("style", "background-color: #00b7ee;cursor: pointer")
        $("#case-order-from").attr("style", "display:none;padding-left: 15px;")
        $("#medical-record-from").attr("style", "display:block;")
    }

    function changeCaseOrder() {
        $("#case-order").attr("style", "background-color: #00b7ee;cursor: pointer")
        $("#medical-record").attr("style", "background-color:rgb(229, 229, 229);cursor: pointer")
        $("#case-order-from").attr("style", "display:block;padding-left: 15px;")
        $("#medical-record-from").attr("style", "display:none;")
    }

    //点击加号克隆处方表单
    var plus = 1;
    function add_case_order_form() {
        if (plus <= 4) {
            //克隆表单
            var cloneForm = $("#form-case-order").clone();
            var id = $("#form-case-order").attr("id")
            cloneForm.attr("id", id + plus)
            cloneForm.find("textarea").val("")
            $("#form-case-order").parent().append(cloneForm)
            //克隆按钮
            var cloneButton = $("#case-order-add").clone();
            cloneButton.attr("style", "margin-right:3px")
            cloneButton.attr("value","处方" + parseInt(plus + 1))
            cloneButton.text("处方" + parseInt(plus + 1))
            $("#case-order-add").parent().append(cloneButton)


            //隐藏其他表单
            $("#form-case-order").attr("style","display:none")
            var cloneId=cloneForm.attr("id")
            for (var i=1;i<=4;i++){
                if (cloneId != id+i){
                    var hiddenId=id+i
                    $("#"+hiddenId).attr("style","display:none")
                }else {
                    $("#"+cloneId).attr("style","display:block")
                }
            }
            plus++
        }else {
            layer.msg("最多添加5个处方",{icon:0,time:1000});
        }
    }

    //单击处方按钮切换表单
    function chose_case_order_form(obj) {
       // var load= layer.load(2,{time:1000})

        layer.msg("加载中",{time:1000},function () {

        //隐藏其他表单
        var buttonText = $(obj).text()//获取当前对象的id
        var cloneId="";
        switch (buttonText) {
            case "处方1" :{
                cloneId="form-case-order"
                break;
            }
            case "处方2" :{
                cloneId="form-case-order1"
                break;
            }
            case "处方3" :{
                cloneId="form-case-order2"
                break;
            }
            case "处方4" :{
                cloneId="form-case-order3"
                break;
            }
            case "处方5" :{
                cloneId="form-case-order4"
                break;
            }

        }
        if (cloneId != "form-case-order"){
            $("#form-case-order").attr("style","display:none")
        }else {
            $("#form-case-order").attr("style","display:block")
        }
        var id="form-case-order"
        for (var i=1;i<=4;i++){
            if (cloneId != id+i){
                var hiddenId=id+i
                $("#"+hiddenId).attr("style","display:none")
            }else {
                $("#"+cloneId).attr("style","display:block")
            }
        }
        });
    }


</script>

<!--业务-->
<script>

    //通过患者手机号查询患者信息
    $(function () {
        var phone= $(patientsPhone).val()
       var idCard= $("#patientsIdcard").val()
        if (phone != ""){
            loadSearchPatinets(phone)
        }
        if (idCard != ""){
            $("#patientsCaseIdCard").val(idCard)
            $("#caseOrderIdCaer").val(idCard)
        }
    })
    function searchPatinets(obj) {
        var phone= $(obj).val()
        loadSearchPatinets(phone)
    }

    function changeIdcard(obj) {
        $("#patientsCaseIdCard").val($("#patientsIdcard").val())
        $("#caseOrderIdCaer").val($("#patientsIdcard").val())
    }

    function loadSearchPatinets(phone) {
        //档案
        $('#dataTable-archives').bootstrapTable({
            url: 'newVisit/getPatientsArchives?patientsPhone='+phone,//ajax请求的url地址
            columns: [ //表格显示数据对应的表头设置，
                {field: 'patientsName', title: '姓名'},
                {field: 'patientsGender', title: '性别'},
                {field: 'patientsAge', title: '年龄'},
                {field: 'patientsPhone', title: '电话'},
                {field: 'patientsIdcard', title: '身份证'},
            ]
        });

        //病历
        $('#dataTable-history').bootstrapTable({
            url: 'newVisit/getPatientsHistory?patientsPhone='+phone,//ajax请求的url地址
            columns: [ //表格显示数据对应的表头设置，
                {field: 'caseResult', title: '病历详情'},
                {field: 'morbidityDate', title: '发病日期'},
                {field: 'acceptsType', title: '接诊类型'},
                {field: 'transmission', title: '是否传染'},
            ]
        });
    }
    //点击图标获取挂号信息
    function showPatientsRegistered() {

        layer.open({
            type: 2,
            title: "选择患者",
            shade: 0.5,
            maxmin:true,
            area: ['700px','550px'],
            content: "newVisit/chocePatinetsManager", //iframe的url，no代表不显示滚动条
        });
    }

    //处方表-添加药品信息弹框
    function case_order_add_medicine() {
        layer.open({
            type: 2,
            title: "添加药品",
            shade: 0.5,
            maxmin:true,
            area: ['700px','550px'],
            content: "newVisit/showMedicine?caseOrderNumber="+$("#caseOrderNumber").val()
        })
    }

    //处方表-添加检查项目费信息弹框
    function case_order_add_check() {
        layer.open({
            type: 2,
            title: "添加检查项目",
            shade: 0.5,
            maxmin:true,
            area: ['700px','550px'],
            content: "newVisit/showCheck?caseOrderNumber="+$("#caseOrderNumber").val()
        })
    }

    //处方表-添加处方附加费信息弹框
    function add_prescription_surcharge() {
        layer.open({
            type: 2,
            title: "添加处方附加费",
            shade: 0.5,
            maxmin:true,
            area: ['500px','350px'],
            content: "newVisit/showPrescriptionSurcharge?caseOrderNumber="+$("#caseOrderNumber").val()
        })
    }


    //刷新页面
    function refresh() {
       location.href="newVisit/newVisitManager"
    }
    //刷新表单
    function refreshTable() {
        $("#dataTable-case-order-tmp").bootstrapTable('refresh')
        $("#dataTable-case-order-tmp-one").bootstrapTable('refresh')
        $("#dataTable-case-order-tmp-two").bootstrapTable('refresh')

    }

    //处方附加表显示
    function showMedicine() {
       refreshTable()
        $("#check_add").attr("style","width: 100%;padding-left: 15px;display:none")
        $("#dataTable-case-order-tmp").attr("style","margin-top: 10px;height: 50px;display:table")
    }

    function showCheck() {
        refreshTable()
        $("#medicine_add").attr("style","width: 100%;padding-left: 15px;display:none")
        $("#dataTable-case-order-tmp-one").attr("style","margin-top: 10px;height: 50px;display:table")
    }
    function showPrescriptionSurcharge() {
        refreshTable()
        $("#dataTable-case-order-tmp-two").attr("style","margin-top: 10px;height: 50px;display:table")
    }

    //表单提交业务
    //患者信息表单
    //表单校验

    function newVisitAdd() {
        //患者信息表单校验
        var patient = $("#form-patients-add").validate({
            rules: {
                patientsName:{
                    required:true
                },
                patientsGender:{
                    required:true
                },
                patientsAge:{
                    required:true
                },
                patientsIdcard:{
                    required:true
                },
                patientsPhone:{
                    required:true
                },
                patientsAddress:{
                    required:true
                }
            },
            success: "valid",
            messages: {
                patientsName:{
                    required:"请填写姓名"
                },
                patientsGender:{
                    required:"！"
                },
                patientsIdcard:{
                    required:"请填写身份证信息"
                },
                patientsAge:{
                    required:"请输入年龄"
                },
                patientsPhone:{
                    required:"请填写手机号"
                },
                patientsAddress:{
                    required:"请填写住址"
                }
            }
        }).form();

        //病历表单校验
        var patientCase=$("#form-patientCase-add").validate({
            rules: {
                morbidityDate:{
                    required:true
                },
                caseTitle:{
                    required:true
                },
                caseResult:{
                    required:true
                },
                doctorTips:{
                    required:true
                }
            },
            success: "valid",
            messages: {
                morbidityDate:{
                    required:"!"
                },
                caseTitle:{
                    required:"请填写患者所述症状"
                },
                caseResult:{
                    required:"请填写诊断详情"
                },
                doctorTips:{
                    required:"请填写医生建议"
                }
            }
        }).form();

        if (patient && patientCase){
            //患者信息表单提交
            $.ajax({
                url:$("#form-patients-add").prop("action"),
                dataType:"json",
                data:$("#form-patients-add").serialize(),
                type:"post",
                success: function (data) {
                        //病历表单提交
                        if (data.code == 1){
                             $.ajax({
                            url:$("#form-patientCase-add").prop("action"),
                            dataType:"json",
                            data:$("#form-patientCase-add").serialize(),
                            type:"post",
                            success: function (data) {
                                //处方表单提交
                                if(data.code == 1){
                                    var formLength=$("form[id^='form-case-order']").size()
                                    var subSuccess=0
                                    $.each($("form[id^='form-case-order']"),function (index,form) {
                                        $.ajax({
                                            url:$("#form-case-order").prop("action"),
                                            dataType:"json",
                                            data:$(form).serialize(),
                                            type:"post",
                                            success: function (data) {
                                                if (data.code == 1){
                                                    subSuccess++
                                                    if (subSuccess ==formLength ){
                                                        layer.msg(data.msg,{icon:data.code,time:1000},function () {
                                                            refresh()
                                                        })
                                                    }
                                                }
                                            }
                                        })
                                    })
                                }

                            }
                        })
                        }
                }
            })




        }
    }


</script>

</html>
